package com.wanxi.util;

import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class CheckIndexInArray {
    public static void main(String[] args) {
        int[] arr = setArrData(10);
        System.out.println(Arrays.toString(arr));
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个数字");
        int num = scanner.nextInt();
        int count = 0;
        for (int i = 0; i < arr.length; i++) {
            if (num == arr[i]) {
                count++;
                System.out.println("当前数字的索引为:" + i);
            }
        }
        System.out.println("出现了" + count + "次");
    }

    /**
     * 对数组进行赋初始值
     *
     * @param length
     */
    private static int[] setArrData(int length) {
        int[] arr = new int[length];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = new Random().nextInt(10);
        }
        return arr;
    }
}
